import java.util.Stack;

class MinStack {
    Stack<Integer> minStack ;
    Stack<Integer> dataStack ;
    public MinStack() {
        minStack = new Stack<>();
        dataStack = new Stack<>();
    }

    public void push(int val) {
        //放元素
        dataStack.push(val);
        if(minStack.isEmpty() || dataStack.peek() <= minStack.peek()){
            minStack.push(val);
        }

        // dataStack.push(val);
        // if(minStack.isEmpty() || val <= minStack.peek())
        //     minStack.push(val);
    }

    public void pop() {
        if (dataStack.isEmpty()){
            return;
        }

        if (dataStack.peek() <= minStack.peek()){
            minStack.pop();
        }
        dataStack.pop();

        // if(dataStack.pop().equals(minStack.peek()))
        // minStack.pop();
    }

    public int top() {
        if(!dataStack.empty()){
            return dataStack.peek();
        }
        return -1;
    }

    public int getMin() {
        if(!minStack.empty()){
            return minStack.peek();
        }
        return -1;
    }
}